package com.egao.orderB.service.impl;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
//import com.egao.orderB.mapper.CustomerMapper;
import com.egao.orderB.entity.Customer;
import com.egao.orderB.service.CustomerService;
import org.springframework.stereotype.Service;
import com.egao.orderB.biz.CustomerBiz;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
//import javax.transaction.Transactional;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 客户管理服务实现类
 * @author : Doman
 * @date : 2021-12-21 15:17:37
 * @version ：1.0
 */
@Service
public class CustomerServiceImpl /*extends ServiceImpl<CustomerMapper, Customer> */implements CustomerService {

	@Autowired
	private CustomerBiz customerBiz;

  @Override
  public JsonResult list(PageResult2<T> page, Customer customer, User loginUser)  throws Exception{
    return customerBiz.list(page,customer,loginUser);
  }

  @Override
  public JsonResult list(Customer customer, User loginUser) {
    return JsonResult.ok().setData(customerBiz.list(customer,loginUser));
  }

  @Override
  public JsonResult getById(Customer customer) {
    return JsonResult.ok().setData(customerBiz.getById(customer));
  }

  @Transactional
  @Override
  public JsonResult save(Customer customer, User loginUser) {
    if (customerBiz.save(customer, loginUser)) {
      return JsonResult.ok("添加成功");
    }
    return JsonResult.error("添加失败");
  }

  @Transactional
  @Override
  public JsonResult update(Customer customer, User loginUser) {
    if (customerBiz.update(customer, loginUser)) {
      return JsonResult.ok("修改成功");
    }
    return JsonResult.error("修改失败");
  }

  @Transactional
  @Override
  public JsonResult remove(Customer customer, User loginUser) {
    if (customerBiz.remove(customer, loginUser)) {
      return JsonResult.ok("删除成功");
    }
    return JsonResult.error("删除失败");
  }

}
